package com.itheima.mall.dubbo.mapper.ums;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.mall.entity.domain.ums.Admin;
import com.itheima.mall.entity.domain.ums.Menu;
import com.itheima.mall.entity.domain.ums.Role;
import jdk.nashorn.internal.objects.annotations.Setter;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface UmsAdminMapper extends BaseMapper<Admin> {

    @Select("select * from ums_role,(select role_id  from ums_admin_role_relation where admin_id = #{adminId}) as al where ums_role.id = al.role_id")
    List<Role> role(Integer adminId);

    @Select("SELECT r.* FROM ums_admin a, ums_admin_role_relation ar,ums_role r WHERE a.id = ar.admin_id and ar.role_id = r.id and a.username = #{username}")
    List<Role> getRoles(String username);
    @Select("<script>SELECT ums_menu.* FROM ums_role_menu_relation, ums_menu WHERE ums_role_menu_relation.menu_id = ums_menu.id and\n" +
            "        ums_role_menu_relation.role_id in\n" +
            "        <foreach\n" +
            "                collection=\"roleIds\" item=\"id\" separator=\",\" open=\"(\" close=\")\">\n" +
            "            #{id}\n" +
            "        </foreach></script>")
    List<Menu> getMenus(List<Integer> roleIds);
}
